home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1995 October / EnigmA AMIGA RUN 01 (1995)(G.R. Edizioni)(IT)[!][issue 1995-10][Aminet 7].iso / Aminet / util / misc / PatchGenSrc.lha / PatchGen.asm < prev    next >
Assembly Source File  |  1993-07-05  |  6KB  |  358 lines

  1. ;_ args ":t/xx" :t/yy ram:z
  2. ; Patch File Generator
  3. ; (c) 1993 MJSoft System Software
  4. ; Martin Mares
  5.  
  6. ;debug    set    1
  7. ;    opt    x+
  8.  
  9. threshold    equ    7    ; Critical size of compared block
  10.     ifnd    LARGE
  11. firstmax    equ    512    ; Parameters of first pass
  12. firstdepth    equ    2048
  13.     elseif
  14. firstmax    equ    2048    ; Parameters of LARGE mode
  15. firstdepth    equ    8192
  16.     endc
  17.  
  18.     include    "macros.h"
  19.  
  20.     arg    arg_from,<FROM/A>
  21.     arg    arg_to,<TO/A>
  22.     arg    arg_topatch,<PTAB/A>
  23.     arg    arg_change,<CHANGE/S>
  24.     ifnd    LARGE
  25.     extrahelp    <Patch File Generator 1.1         (c) 1993 MJSoft System Software, Martin Mares>
  26.     elseif
  27.     extrahelp    <Patch File Generator 1.1L        (c) 1993 MJSoft System Software, Martin Mares>
  28.     endc
  29.  
  30.     start
  31.  
  32.     get.l    arg_from,a2
  33.     bsr    loadfile
  34.     put.l    d0,fromfile
  35.     put.l    d1,fromlen
  36.     dv.l    fromfile
  37.     dv.l    fromlen
  38.  
  39.     get.l    arg_to,a2
  40.     bsr    loadfile
  41.     put.l    d0,tofile
  42.     put.l    d1,tolen
  43.     dv.l    tofile
  44.     dv.l    tolen
  45.  
  46.     move.l    d1,d0
  47.     add.l    #1024,d0
  48.     call    ArpAlloc
  49.     put.l    d0,patchto
  50.     dv.l    patchto
  51.  
  52.     move.l    d0,a6    ; A6 points to patch table
  53.  
  54.     get.l    fromlen,d5    ; D5 points to 1st byte after src file
  55.     get.l    tolen,d6    ; D6 ... dest file
  56.     move.l    #'MJPa',(a6)+
  57.     move.l    #'tch'*256+1,(a6)+
  58.     move.l    d5,(a6)+
  59.     move.l    d6,(a6)+
  60.     get.l    fromfile,a2    ; A2 points to source file contents
  61.     get.l    tofile,a3    ; A3 points to dest. file contents
  62.     move.l    a2,a0
  63.     move.l    d5,d0
  64.     moveq    #0,d1
  65.     moveq    #0,d2
  66. chs1    move.b    (a0)+,d2
  67.     add.l    d2,d1
  68.     ror.l    #1,d1
  69.     subq.l    #1,d0
  70.     bne.s    chs1
  71.     move.l    d1,(a6)+
  72.  
  73.     add.l    a2,d5
  74.     add.l    a3,d6
  75.     tsv.l    arg_change
  76.     beq.s    compare
  77.     move.l    a2,a0
  78.     move.l    a3,a1
  79. change1    cmp.l    d6,a1
  80.     bcc.s    change0
  81.     cmp.l    d5,a0
  82.     bcs.s    1$
  83.     move.l    a2,a0
  84. 1$    move.b    (a0)+,d0
  85.     eor.b    d0,(a1)+
  86.     bra.s    change1
  87.  
  88. change0    moveq    #3,d1
  89.     move.l    d5,d0
  90.     sub.l    a2,d0
  91.     sub.l    a0,a0
  92.     bsr    writechunk
  93.     moveq    #5,d1
  94.     move.l    d6,d0
  95.     sub.l    a3,d0
  96.     move.l    a3,a0
  97.     bsr    writechunk
  98.     bra    totalend
  99.  
  100. compare
  101.  
  102.     mpush    d1-d7/a0-a6
  103.     write    <.>
  104.     lea    msgfail(pc),a1
  105.     call    CheckAbort
  106.     mpop    d1-d7/a0-a6
  107.  
  108.     moveq    #-1,d0        ; Identical bytes
  109. comp1    addq.l    #1,d0
  110.     cmp.l    d5,a2
  111.     bcc.s    comp3
  112.     cmp.l    d6,a3
  113.     bcc.s    comp3
  114.     cmp.b    (a2)+,(a3)+
  115.     beq.s    comp1
  116. comp3    tst.l    d0
  117.     beq.s    comp2
  118.     sub.l    a0,a0
  119.     moveq    #4,d1
  120.     bsr    writechunk
  121.  
  122. comp2    cmp.l    d5,a2    ; End of source file ?
  123.     bcc    srcend
  124.     cmp.l    d6,a3    ; End of dest file ?
  125.     bcc    destend
  126.     subq.l    #1,a2
  127.     subq.l    #1,a3
  128.     put.l    a2,olda2
  129.     dv.l    olda2
  130.     dv.l    currmax
  131.     put.l    #firstmax,currmax
  132.     move.l    #firstdepth,d7
  133. comp4    moveq    #1,d0
  134.     move.l    d5,d1
  135.     sub.l    a2,d1
  136.     move.l    d6,d3    ; D3=bytes to end
  137.     sub.l    a3,d3
  138.     cmp.l    d1,d3
  139.     bcs.s    compit0
  140.     exg.l    d1,d3
  141. compit0    cmp.l    currmax-v(a4),d3
  142.     bcs.s    compit2
  143.     get.l    currmax,d3
  144.     bra.s    compit2
  145.  
  146. compit1    move.b    0(a2,d0.l),d1
  147.     move.b    0(a3,d0.l),d2
  148.     cmp.b    d1,d2
  149.     beq.s    comppt1
  150.     cmp.b    (a2),d2
  151.     beq.s    compin1
  152.     cmp.b    (a3),d1
  153.     beq.s    compde1
  154. compnext    addq.l    #1,d0
  155. compit2    subq.l    #1,d3
  156.     bne.s    compit1
  157.     bra.s    comptrx
  158.  
  159. comppt1    moveq    #threshold,d1    ; Critical size
  160.     lea    0(a2,d0.l),a0
  161.     lea    0(a3,d0.l),a1
  162. 1$    cmp.b    (a0)+,(a1)+
  163.     dbne    d1,1$
  164.     bne.s    compnext
  165. comppt2    moveq    #1,d1
  166.     move.l    a3,a0
  167.     bsr    writechunkz
  168.     add.l    d0,a2
  169.     add.l    d0,a3
  170.     bra    compare
  171.  
  172. compin1    moveq    #threshold,d1
  173.     move.l    a2,a0
  174.     lea    0(a3,d0.l),a1
  175. 1$    cmp.b    (a0)+,(a1)+
  176.     dbne    d1,1$
  177.     bne.s    compnext
  178.     moveq    #2,d1
  179.     move.l    a3,a0
  180.     bsr    writechunkz
  181.     add.l    d0,a3
  182.     bra    compare
  183.  
  184. compde1    moveq    #threshold,d1
  185.     lea    0(a2,d0.l),a0
  186.     move.l    a3,a1
  187. 1$    cmp.b    (a0)+,(a1)+
  188.     dbne    d1,1$
  189.     bne.s    compnext
  190.     moveq    #3,d1
  191.     sub.l    a0,a0
  192.     bsr    writechunkz
  193.     add.l    d0,a2
  194.     bra    compare
  195.  
  196. comptrx    addq.l    #1,a2
  197.     addq.l    #1,a3
  198.     subq.l    #1,d7
  199.     beq.s    compit3
  200.     cmp.l    d5,a2
  201.     bcc.s    compit3
  202.     cmp.l    d6,a3
  203.     bcs    comp4
  204. compit3    move.l    a2,d0
  205.     sub.l    olda2-v(a4),d0
  206.     sub.l    d0,a2
  207.     sub.l    d0,a3
  208.     cmp.l    #firstmax,currmax-v(a4)
  209.     bne.s    comppt2
  210.     moveq    #-1,d7
  211.     put.l    d7,currmax
  212.     bra    comp4
  213.  
  214. srcend    cmp.l    d6,a3    ; End of dest file ?
  215.     bcc.s    totalend
  216.     moveq    #2,d1
  217.     move.l    d6,d0
  218.     sub.l    a3,d0
  219.     move.l    a3,a0
  220.     bsr    writechunk
  221. totalend    sf    (a6)+
  222.     move.l    a6,d3
  223.     get.l    arg_topatch,d1
  224.     move.l    #1006,d2
  225.     call    arp,ArpOpen
  226.     move.l    d0,d1
  227.     errc.ne    <Unable to open destination file!>
  228.     get.l    patchto,d2
  229.     sub.l    d2,d3
  230.     call    Write
  231.     cmp.l    d0,d3
  232.     errc.eq    <Error writing destination file!>
  233.  
  234.     push    copied-v(a4)
  235.     dv.l    copied
  236.     push    tolen-v(a4)
  237.     push    fromlen-v(a4)
  238.     push    d3
  239.     move.l    a7,a1
  240.     dm    finalt,<Done. Patch file size=%ld (original=%ld, new=%ld, changed=%ld)',10,'>
  241.     gett    finalt,a0
  242.     call    Printf
  243.     lea    16(a7),a7
  244.     rts
  245.  
  246. destend    moveq    #3,d1
  247.     move.l    d5,d0
  248.     sub.l    a2,d0
  249.     sub.l    a0,a0
  250.     bsr.s    writechunk
  251.     bra.s    totalend
  252.  
  253. writechunkz    cmp.l    olda2-v(a4),a2
  254.     beq.s    writechunk
  255.     mpush    d0-d1/a0
  256.     move.l    a2,d0
  257.     sub.l    olda2-v(a4),d0
  258.     moveq    #1,d1
  259.     move.l    a3,a0
  260.     sub.l    d0,a0
  261.     put.l    a2,olda2
  262.     bsr.s    writechunk
  263.     mpop    d0-d1/a0
  264.  
  265. writechunk
  266.     ifd    debug
  267.     mpush    d0-d7/a0-a6
  268.     push    d0
  269.     move.l    a0,d0
  270.     sub.l    tofile-v(a4),d0
  271.     bcc.s    1$
  272.     moveq    #-1,d0
  273. 1$    push    d0
  274.     push    d1
  275.     dm    msg1,<%ld    @%ld    l=%ld',10,'>
  276.     gett    msg1,a0
  277.     move.l    a7,a1
  278.     call    arp,Printf
  279.     lea    12(a7),a7
  280.     mpop    d0-d7/a0-a6
  281.     endc
  282.  
  283. wrch    mpush    d0-d7/a0-a5
  284.     move.l    d0,d2
  285.     cmp.l    #32,d0
  286.     bcs.s    1$
  287.     moveq    #0,d2
  288. 1$    lsl.b    #5,d1
  289.     or.b    d1,d2
  290.     move.b    d2,(a6)+
  291.     cmp.l    #32,d0
  292.     bcs.s    2$
  293.     cmp.l    #65536,d0
  294.     bcs.s    5$
  295.     sf    (a6)+
  296.     sf    (a6)+
  297.     swap    d0
  298.     bsr.s    putword
  299.     swap    d0
  300. 5$    bsr.s    putword
  301. 2$    move.l    a0,d1
  302.     beq.s    3$
  303.     add.l    d0,copied-v(a4)
  304. 4$    move.b    (a0)+,(a6)+
  305.     subq.l    #1,d0
  306.     bne.s    4$
  307. 3$    mpop    d0-d7/a0-a5
  308.     rts
  309.  
  310. putword    ror.w    #8,d0
  311.     move.b    d0,(a6)+
  312.     ror.w    #8,d0
  313.     move.b    d0,(a6)+
  314.     rts
  315.  
  316. loadfile    move.l    a2,d1
  317.     move.l    #1005,d2
  318.     call    arp,Open
  319.     move.l    d0,d7
  320.     bne.s    load1
  321.     dm    errf1,<Unable to open %s!',10,'>
  322.     gett    errf1,a0
  323. loaderr    push    a2
  324.     move.l    a7,a1
  325.     call    arp,Printf
  326.     bra    failed    
  327.  
  328. load1    move.l    d7,d1
  329.     moveq    #0,d2
  330.     moveq    #1,d3
  331.     call    Seek
  332.     move.l    d7,d1
  333.     moveq    #-1,d3
  334.     call    Seek
  335.     move.l    d0,d3
  336.     addq.l    #8,d0
  337.     call    ArpAlloc
  338.     move.l    d0,d2
  339.     bne.s    load2
  340.     move.l    d7,d1
  341.     call    Close
  342.     dm    errf2,<No memory for %s!',10,'>
  343.     gett    errf2,a0
  344.     bra.s    loaderr
  345.  
  346. load2    move.l    d7,d1
  347.     call    Read
  348.     move.l    d0,d6
  349.     move.l    d7,d1
  350.     call    Close
  351.     cmp.l    d6,d3
  352.     dm    errf3,<Error reading %s!',10,'>
  353.     gett    errf2,a0
  354.     bne.s    loaderr
  355.     move.l    d2,d0
  356.     move.l    d3,d1
  357.     rts
  358.